﻿// 
// SoapTrace.Net - A soap message monitoring utility. 
// 
// Copyright (C) 2004 Matthew Ward
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
// Matthew Ward (mrward@users.sourceforge.net)
// 



using System;
using System.Collections;
using System.Net.Sockets;

namespace SoapTrace.Core.Communication
{
	/// <summary>
	///     <para>
	///       A collection that stores <see cref='ProxyChannel'/> objects.
	///    </para>
	/// </summary>
	/// <seealso cref='ProxyChannelCollection'/>
	public sealed class ProxyChannelCollection : CollectionBase 
	{
		
		/// <summary>
		///     <para>
		///       Initializes a new instance of <see cref='ProxyChannelCollection'/>.
		///    </para>
		/// </summary>
		public ProxyChannelCollection( )
		{
		}
		
		/// <summary>
		///     <para>
		///       Initializes a new instance of <see cref='ProxyChannelCollection'/> based on another <see cref='ProxyChannelCollection'/>.
		///    </para>
		/// </summary>
		/// <param name='val'>
		///       A <see cref='ProxyChannelCollection'/> from which the contents are copied
		/// </param>
		public ProxyChannelCollection(ProxyChannelCollection val)
		{
			this.AddRange(val);
		}
		
		/// <summary>
		///     <para>
		///       Initializes a new instance of <see cref='ProxyChannelCollection'/> containing any array of <see cref='ProxyChannel'/> objects.
		///    </para>
		/// </summary>
		/// <param name='val'>
		///       A array of <see cref='ProxyChannel'/> objects with which to intialize the collection
		/// </param>
		public ProxyChannelCollection(ProxyChannel[] val)
		{
			this.AddRange(val);
		}
		
		/// <summary>
		/// <para>Represents the entry at the specified index of the <see cref='ProxyChannel'/>.</para>
		/// </summary>
		/// <param name='index'><para>The zero-based index of the entry to locate in the collection.</para></param>
		/// <value>
		///    <para> The entry at the specified index of the collection.</para>
		/// </value>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='index'/> is outside the valid range of indexes for the collection.</exception>
		public ProxyChannel this[int index] 
		{
			get 
			{
				return ((ProxyChannel)(List[index]));
			}
			set 
			{
				List[index] = value;
			}
		}
		
		/// <summary>
		///    <para>Adds a <see cref='ProxyChannel'/> with the specified value to the 
		///    <see cref='ProxyChannelCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='ProxyChannel'/> to add.</param>
		/// <returns>
		///    <para>The index at which the new element was inserted.</para>
		/// </returns>
		/// <seealso cref='ProxyChannelCollection.AddRange'/>
		public int Add(ProxyChannel val)
		{
			return List.Add(val);
		}
		
		/// <summary>
		/// <para>Copies the elements of an array to the end of the <see cref='ProxyChannelCollection'/>.</para>
		/// </summary>
		/// <param name='val'>
		///    An array of type <see cref='ProxyChannel'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <seealso cref='ProxyChannelCollection.Add'/>
		public void AddRange(ProxyChannel[] val)
		{
			for (int i = 0; i < val.Length; i++) 
			{
				this.Add(val[i]);
			}
		}
		
		/// <summary>
		///     <para>
		///       Adds the contents of another <see cref='ProxyChannelCollection'/> to the end of the collection.
		///    </para>
		/// </summary>
		/// <param name='val'>
		///    A <see cref='ProxyChannelCollection'/> containing the objects to add to the collection.
		/// </param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <seealso cref='ProxyChannelCollection.Add'/>
		public void AddRange(ProxyChannelCollection val)
		{
			for (int i = 0; i < val.Count; i++)
			{
				this.Add(val[i]);
			}
		}
		
		/// <summary>
		/// <para>Gets a value indicating whether the 
		///    <see cref='ProxyChannelCollection'/> contains the specified <see cref='ProxyChannel'/>.</para>
		/// </summary>
		/// <param name='val'>The <see cref='ProxyChannel'/> to locate.</param>
		/// <returns>
		/// <para><see langword='true'/> if the <see cref='ProxyChannel'/> is contained in the collection; 
		///   otherwise, <see langword='false'/>.</para>
		/// </returns>
		/// <seealso cref='ProxyChannelCollection.IndexOf'/>
		public bool Contains(ProxyChannel val)
		{
			return List.Contains(val);
		}
		
		/// <summary>
		/// <para>Copies the <see cref='ProxyChannelCollection'/> values to a one-dimensional <see cref='System.Array'/> instance at the 
		///    specified index.</para>
		/// </summary>
		/// <param name='array'><para>The one-dimensional <see cref='System.Array'/> that is the destination of the values copied from <see cref='ProxyChannelCollection'/> .</para></param>
		/// <param name='index'>The index in <paramref name='array'/> where copying begins.</param>
		/// <returns>
		///   <para>None.</para>
		/// </returns>
		/// <exception cref='System.ArgumentException'><para><paramref name='array'/> is multidimensional.</para> <para>-or-</para> <para>The number of elements in the <see cref='ProxyChannelCollection'/> is greater than the available space between <paramref name='arrayIndex'/> and the end of <paramref name='array'/>.</para></exception>
		/// <exception cref='System.ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception>
		/// <exception cref='System.ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception>
		/// <seealso cref='System.Array'/>
		public void CopyTo(ProxyChannel[] array, int index)
		{
			List.CopyTo(array, index);
		}
		
		/// <summary>
		///    <para>Returns the index of a <see cref='ProxyChannel'/> in 
		///       the <see cref='ProxyChannelCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='ProxyChannel'/> to locate.</param>
		/// <returns>
		/// <para>The index of the <see cref='ProxyChannel'/> of <paramref name='value'/> in the 
		/// <see cref='ProxyChannelCollection'/>, if found; otherwise, -1.</para>
		/// </returns>
		/// <seealso cref='ProxyChannelCollection.Contains'/>
		public int IndexOf(ProxyChannel val)
		{
			return List.IndexOf(val);
		}
		
		/// <summary>
		/// <para>Inserts a <see cref='ProxyChannel'/> into the <see cref='ProxyChannelCollection'/> at the specified index.</para>
		/// </summary>
		/// <param name='index'>The zero-based index where <paramref name='value'/> should be inserted.</param>
		/// <param name='val'>The <see cref='ProxyChannel'/> to insert.</param>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='ProxyChannelCollection.Add'/>
		public void Insert(int index, ProxyChannel val)
		{
			List.Insert(index, val);
		}
		
		/// <summary>
		///    <para>Returns an enumerator that can iterate through 
		///       the <see cref='ProxyChannelCollection'/> .</para>
		/// </summary>
		/// <returns><para>None.</para></returns>
		/// <seealso cref='System.Collections.IEnumerator'/>
		public new ProxyChannelEnumerator GetEnumerator()
		{
			return new ProxyChannelEnumerator(this);
		}
		
		/// <summary>
		///    <para> Removes a specific <see cref='ProxyChannel'/> from the 
		///    <see cref='ProxyChannelCollection'/> .</para>
		/// </summary>
		/// <param name='val'>The <see cref='ProxyChannel'/> to remove from the <see cref='ProxyChannelCollection'/> .</param>
		/// <returns><para>None.</para></returns>
		/// <exception cref='System.ArgumentException'><paramref name='value'/> is not found in the Collection. </exception>
		public void Remove(ProxyChannel val)
		{
			List.Remove(val);
		}
		
		/// <summary>
		/// The proxy channel enumerator.
		/// </summary>
		public class ProxyChannelEnumerator : IEnumerator
		{
			IEnumerator baseEnumerator;
			IEnumerable temp;
			
			/// <summary>
			/// Creates a new instance of this class.
			/// </summary>
			/// <param name="mappings">A collection of proxy channels.</param>
			public ProxyChannelEnumerator(ProxyChannelCollection mappings)
			{
				this.temp = ((IEnumerable)(mappings));
				this.baseEnumerator = temp.GetEnumerator();
			}
			
			/// <summary>
			/// Gets the item at the current position.
			/// </summary>
			public ProxyChannel Current 
			{
				get 
				{
					return ((ProxyChannel)(baseEnumerator.Current));
				}
			}
			
			/// <summary>
			/// Gets the item at the current position.
			/// </summary>
			object IEnumerator.Current 
			{
				get 
				{
					return baseEnumerator.Current;
				}
			}

			/// <summary>
			/// Moves to the next item in the collection.
			/// </summary>
			/// <returns>A status flag indicating whether
			/// the move was successful.</returns>
			public bool MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			/// <summary>
			/// Moves to the next item in the collection.
			/// </summary>
			/// <returns>A status flag indicating whether
			/// the move was successful.</returns>
			bool IEnumerator.MoveNext()
			{
				return baseEnumerator.MoveNext();
			}
			
			/// <summary>
			/// Resets the enumerator.
			/// </summary>
			public void Reset()
			{
				baseEnumerator.Reset();
			}
			
			void IEnumerator.Reset()
			{
				baseEnumerator.Reset();
			}
		}
	}
}
